package org.ehe.finance.payable.mapper;

import lombok.Data;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.ehe.common.mybatis.core.mapper.BaseMapperPlus;
import org.ehe.finance.payable.domain.ErpFinancePayable;
import org.ehe.finance.payable.domain.vo.PayableResponseVO;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;

/**
 *
 * @author :zhangnn
 * @className :PayableMapper
 * @description: TODO
 * @date 2025-09-02 10:09:04
 */
public interface PayableMapper extends BaseMapperPlus<ErpFinancePayable, PayableResponseVO> {
    /**
     * 根据供应商统计应付金额
     */
    List<PayableStatistics> statisticsBySupplier(@Param("tenantId") String tenantId);

    /**
     * 查询即将到期的应付账款
     */
    List<ErpFinancePayable> selectDuePayables(@Param("tenantId") String tenantId,
                                              @Param("startDate") LocalDate startDate,
                                              @Param("endDate") LocalDate endDate);

    /**
     * 更新付款金额
     */
    int updatePaymentAmount(@Param("payableId") Long payableId,
                            @Param("paymentAmount") BigDecimal paymentAmount,
                            @Param("tenantId") String tenantId);

    /**
     * 应付账款统计数据内部类
     */
    @Data
    class PayableStatistics {
        private Long supplierId;
        private BigDecimal totalAmount;
        private BigDecimal paidAmount;
        private BigDecimal unpaidAmount;
    }
}
